#pragma once

#include <iostream>
#include <pthread.h>
#include <string>

class Mutex
{
public:
    Mutex(pthread_mutex_t *mutex)
        : _mutex(mutex)
    {}

    void lock()
    {
        // 上锁
        pthread_mutex_lock(_mutex);
    }

    void unlock()
    {
        // 解锁
        pthread_mutex_unlock(_mutex);
    }

    ~Mutex() {}

private:
    pthread_mutex_t *_mutex;
};

class lockGuard
{
public:
    //利用RAII思想
    lockGuard(pthread_mutex_t *mutex)
        : _mutex(mutex)
    {
        _mutex.lock();
    }

    ~lockGuard()
    {
        _mutex.unlock();
    }

private:
    Mutex _mutex;
};